package com.sun.filesigndemo.common.statusCode;

import java.util.HashMap;
import java.util.Map;

public class ResultMsg {
    /**
     * 返回无数据的成功结果
     *
     * @return JSON结果
     */
    public static Map<String, Object> success()
    {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", GlobalResultStatusEnum.SUCCESS.getCode());
        map.put("message", "成功");
        return map;
    }

    /**
     * 返回成功消息
     *
     * @return JSON结果
     */
    public static Map<String, Object> successMsg(Object message)
    {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", GlobalResultStatusEnum.SUCCESS.getCode());
        map.put("message", message);
        return map;
    }


    /**
     * 返回成功数据
     * @param data 成功数据
     * @return
     */
    public static Map<String, Object> successData(Object data)
    {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", GlobalResultStatusEnum.SUCCESS.getCode());
        map.put("data", data);
        return map;
    }

    /**
     * 返回自定义状态
     *
     * @return JSON结果
     */
    public static Map<String, Object> result(ResultStatus resultStatus)
    {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", resultStatus.getCode());
        map.put("message", resultStatus.getMsg());
        return map;
    }
    /**
     * 返回自定义状态和数据
     *
     * @return JSON结果
     */
    public static Map<String, Object> result(ResultStatus resultStatus, Object data)
    {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", resultStatus.getCode());
        map.put("message", resultStatus.getMsg());
        map.put("data", data);
        return map;
    }


    /**
     * 返回失败结果
     *
     * @return JSON结果
     */
    public static Map<String, Object> fail(GlobalResultStatusEnum globalResultStatusEnum)
    {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", globalResultStatusEnum.getCode());
        map.put("message", globalResultStatusEnum.getMsg());
        return map;
    }

    /**
     * 返回失败结果
     *
     * @return JSON结果
     */
    public static Map<String, Object> fail()
    {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", GlobalResultStatusEnum.ERROR.getCode());
        map.put("message", GlobalResultStatusEnum.ERROR.getMsg());
        return map;
    }

    /**
     * 返回失败结果
     *
     * @return JSON结果
     */
    public static Map<String, Object> fail(String msg)
    {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", 700);
        map.put("message", msg);
        return map;
    }

    /**
     * 返回失败结果
     *
     * @param data 数据节点对象
     * @return JSON结果
     */
    public static Map<String, Object> fail(GlobalResultStatusEnum resultStatus, Object data)
    {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", resultStatus.getCode());
        map.put("message", resultStatus.getMsg());
        map.put("data", data);
        return map;
    }
}
